
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>线程的状态 - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>线程的状态 - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">理论</div>
          <div class="card-question">Java线程在其生命周期中包含哪六种主要状态？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">理论</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">Java线程的六种主要状态分别是：NEW (新建)、RUNNABLE (可运行)、BLOCKED (阻塞)、WAITING (等待)、TIMED_WAITING (超时等待) 和 TERMINATED (终止)。</div>
          </div>
          <div class="card-source">来源: 线程的六种状态</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">线程是如何进入 BLOCKED (阻塞) 状态的？它又将如何返回到 RUNNABLE 状态？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">当一个线程尝试进入一个被其他线程占用的同步块或方法时，它会进入 BLOCKED 状态。一旦该线程成功获取到锁，它就会返回到 RUNNABLE 状态。</div>
          </div>
          <div class="card-source">来源: 3. BLOCKED (阻塞)</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">调用哪些典型方法可以使一个线程进入 WAITING (等待) 状态？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">典型的使线程进入 WAITING 状态的方法包括调用 Object.wait()、Thread.join() 和 LockSupport.park()。</div>
          </div>
          <div class="card-source">来源: 4. WAITING (等待)</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">理论</div>
          <div class="card-question">为什么说理解线程状态对于预防死锁这类并发问题至关重要？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">理论</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">因为死锁发生在两个或多个线程互相等待对方释放资源的情况下，这会导致相关线程永远处于 BLOCKED 状态。通过监控线程状态，可以有效地检测和预防死锁的发生。</div>
          </div>
          <div class="card-source">来源: 2. 预防并发问题</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">WAITING (等待) 状态和 TIMED_WAITING (超时等待) 状态之间有何主要区别？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">主要区别在于等待时间。WAITING 状态的线程需要等待另一个线程显式地唤醒它，是无限期等待。而 TIMED_WAITING 状态的线程则是在等待一个指定的时间后可以自动唤醒。</div>
          </div>
          <div class="card-source">来源: 4. WAITING (等待) 和 5. TIMED_WAITING (超时等待)</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">Java中的 RUNNABLE (可运行) 状态具体包含了操作系统层面的哪两种情况？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">RUNNABLE 状态包括了操作系统层面上的“运行中”和“就绪”两种状态。这意味着处于 RUNNABLE 状态的线程可能正在执行任务，也可能在等待CPU分配时间片。</div>
          </div>
          <div class="card-source">来源: 2. RUNNABLE (可运行)</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">模式</div>
          <div class="card-question">为了优化线程的生命周期管理并避免频繁创建和销毁线程的开销，文档推荐了什么方法？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">模式</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">文档推荐使用线程池（如 ExecutorService）来管理线程的创建和销毁。线程池通过复用现有的线程实例，可以提高资源的利用率和系统的整体吞吐量。</div>
          </div>
          <div class="card-source">来源: 2. 优化线程的生命周期管理</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">文档中提到了哪些可用于监控和调试线程状态的Java工具？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">文档中提到的监控工具包括 jstack、jconsole、VisualVM，以及像Java Flight Recorder、New Relic这样的性能分析工具。</div>
          </div>
          <div class="card-source">来源: 1. 线程状态的监控与调试</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">使用 Condition 接口的 await() 方法会如何影响线程的状态转换？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">当线程调用 await() 方法时，它会释放持有的锁并从 RUNNABLE 状态进入 WAITING 状态。当被 signal() 或 signalAll() 唤醒后，线程会尝试重新获取锁，先进入 BLOCKED 状态，成功获取锁后最终转换回 RUNNABLE 状态。</div>
          </div>
          <div class="card-source">来源: 2. Condition 的作用和线程状态影响</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
